
/*
Description:

*/

#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution {
public:
	string countAndSay(int n) {
		if (n == 0) return "";
		string res = "1";
		while (--n) {
			string cur = "";
			for (int i = 0; i < res.size(); i++) {
				int count = 1;
				while ((i + 1 < res.size()) && (res[i] == res[i + 1])) {
					count++;
					i++;
				}
				cur += to_string(count) + res[i];
			}
			res = cur;
		}
		return res;
	}

	string countAndSay0(int n)
	{
		string s = "";
		string ss= "";

		int count = 0;
		char o = 'o';
		char c;

		if (n == 1)
		{
			return "1";
		}
		else
		{
			s = countAndSay(n - 1);
			while (!s.empty())
			{
				c = s.front();
				
				if (c != o)
				{
					if (o == 'o') //first ch
					{						
						o = c;
						count++;
					}
					else
					{
						ss.push_back('0' + count);
						ss.push_back(o);
						count = 1;
						o = c;
					}					
				}
				else
				{
					count++;
				}

				//s.erase(0,1);				
				s.erase(s.begin());
			}
			ss.push_back('0' + count);
			ss.push_back(c);

			return ss;
		}
		
	}
};

int _countAndSay()
{	
	int num = 6;
	Solution solu;
	string result;

	result = solu.countAndSay(num);

	cout << "num: " << num << endl;
	cout << "str: " << result << endl;
	return 0;
}